<template lang="html">
    <div class="message">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;首页消息列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-button type="primary" round @click="urlAdd()"><i class="el-icon-plus"> </i>&nbsp;&nbsp;新增消息</el-button>
            <div style="height:20px;"></div>
            <el-table :data="messageList" style="width: 100%" v-loading="loading">
                <el-table-column prop="id" label="ID" width="80"></el-table-column>
                <el-table-column prop="content_cn" label="内容(中文)" width="300" align="center"></el-table-column>
                <el-table-column prop="content_en" label="内容(英文)" width="300" align="center"></el-table-column>
                <el-table-column label="类别"  align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.type == 1">系统</div>
                        <div v-if="scope.row.type == 2">交易</div>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button size="small" type="text"  @click="changeEdit(scope.row)" >编辑</el-button>
                        <el-button class="del"  size="small" type="text"  @click="changeDelete(scope.row)" >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" v-show="total>1">
                <el-pagination 
                @current-change="handleCurrentChange" 
                :page-size="pageSize"  
                layout="total,prev, pager, next" 
                :total="total"
                >
                </el-pagination>
            </div>
        </div>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {getMessageList,postMessageDel} from '@/api/message/list'
    export default {
        name: "message",
        data() {
            return {
                loading:true,//加载中
                pageIndex:1,
                pageSize:10,
                total:0,//总条数
                messageList:[],//消息列表，
                messageClass:[
                    {
                        value: '1',
                        label: '系统'
                    },
                    {
                        value: '2',
                        label: '交易'
                    },
                ],
                messageValue:'系统',
                messageType:1,//默认显示系统，类型：1系统、2交易
                TypeValue:'',//类别
                delVisible:false,//删除弹框
                Id:0,//轮播图id
            }
        },
        created(){
            //获取分类列表
            this.getMessageList();
        },
        mounted() {
            
        },
        methods: {
            //获取轮播图列表
            getMessageList(){
                getMessageList(this.pageIndex,this.pageSize).then(res => {
                    // console.log(res);
                    this.messageList = [];
                    this.messageList = res.data.list;
                    this.loading = false;//加载中
                    var list = res.data.list;
                    this.total = res.data.total;
                })
            },
            //页码
            handleCurrentChange(index){
                this.loading = true;//加载中
                this.pageIndex = index;//保存页码
                this.getMessageList();//重新加载数据
            },
            //跳转编辑
            changeEdit(ev){
                this.$router.push({ path: '/message/edit',query:{id:ev.id}});
            },
            //跳转新增
            urlAdd(){
                this.$router.push({ path: '/message/add'});
            },
            //删除
            changeDelete(ev){
                this.Id = ev.id;//保存轮播图id
                this.delVisible = true;//打开弹框
            },
            //确定，删除操作
            deleteRow(){
                postMessageDel(this.Id).then(res => {
                    if(res.code == 200){
                        this.$message({
                            message: '删除成功！',
                            type: 'success'
                        });
                        this.getMessageList();//重新加载列表
                    }else {
                        this.$message.error('删除失败！');
                    }
                })
                this.delVisible = false;//关闭弹框
            },
        }
    }
</script>

<style lang="css" scoped>
.del {
    color: #f00;
}
</style>
